package com.power.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.power.mapper.TClueRemarkMapper;
import com.power.model.TClueRemark;
import com.power.model.TUser;
import com.power.query.ClueRemarkQuery;
import com.power.service.ClueRemarkService;
import com.power.util.LoginInfoUtil;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class ClueRemarkServiceImpl implements ClueRemarkService {
    @Resource
    private TClueRemarkMapper tClueRemarkMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int saveClueRemark(ClueRemarkQuery clueRemarkQuery) {
        TClueRemark tClueRemark = new TClueRemark();
        BeanUtils.copyProperties(clueRemarkQuery, tClueRemark);
        TUser tUser = LoginInfoUtil.getUserFromToken(clueRemarkQuery.getToken());
        tClueRemark.setCreateBy(tUser.getId());
        tClueRemark.setCreateTime(new Date());
        return tClueRemarkMapper.insertSelective(tClueRemark);
    }

    @Override
    public PageInfo<TClueRemark> selectClueRemarkByPage(Integer currentPage, Integer pageSize, ClueRemarkQuery clueRemarkQuery) {
        PageHelper.startPage(currentPage, pageSize);
        List<TClueRemark> clueRemarkList = tClueRemarkMapper.selectClueRemarkByPage(clueRemarkQuery);
        PageInfo<TClueRemark> pageInfo = new PageInfo<>(clueRemarkList);
        return pageInfo;
    }
}
